<template>
  <!-- <vue-particles
    id="tsparticles"
    :particlesInit="particlesInit"
    :particlesLoaded="particlesLoaded"
    :options="{
      background: {
        color: {
          value: '#0d47a1',
        },
      },
      fpsLimit: 120,
      interactivity: {
        events: {
          onClick: {
            enable: true,
            mode: 'push',
          },
          onHover: {
            enable: true,
            mode: 'repulse',
          },
          resize: true,
        },
        modes: {
          bubble: {
            distance: 400,
            duration: 2,
            opacity: 0.8,
            size: 40,
          },
          push: {
            quantity: 4,
          },
          repulse: {
            distance: 200,
            duration: 0.4,
          },
        },
      },
      particles: {
        color: {
          value: '#ffffff',
        },
        links: {
          color: '#ffffff',
          distance: 150,
          enable: true,
          opacity: 0.5,
          width: 1,
        },
        collisions: {
          enable: true,
        },
        move: {
          direction: 'none',
          enable: true,
          outMode: 'bounce',
          random: false,
          speed: 6,
          straight: false,
        },
        number: {
          density: {
            enable: true,
            area: 800,
          },
          value: 80,
        },
        opacity: {
          value: 0.5,
        },
        shape: {
          type: 'circle',
        },
        size: {
          random: true,
          value: 5,
        },
      },
      detectRetina: true,
    }"
  /> -->
  <div class="h100 login">
    <el-card class="box-card">
      <template #header>
        <div class="card-header">
          <span>登录</span>
        </div>
      </template>
      <el-form
        ref="ruleFormRef"
        :model="ruleForm"
        status-icon
        :rules="rules"
        class="demo-ruleForm"
      >
        <el-form-item prop="userName">
          <el-input v-model="ruleForm.userName" autocomplete="off" />
        </el-form-item>
        <el-form-item prop="passWord">
          <el-input
            v-model="ruleForm.passWord"
            type="password"
            autocomplete="off"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            class="w100"
            type="primary"
            @click="submitForm(ruleFormRef)"
            >登录</el-button
          >
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
<script setup>
import { ref } from "vue";
import { loadSlim } from "tsparticles-slim";
import { userFormRules } from "@/hooks";
const ruleFormRef = ref();

const UserName = (rule, value, callback) => {
  if (value == "") {
    callback(new Error("请输入账号"));
  } else {
    callback();
  }
};

const passWord = (rule, value, callback) => {
  if (value == "") {
    callback(new Error("请输入密码"));
  } else {
    callback();
  }
};


const { ruleForm, rules, submitForm } = userFormRules(
  {
    userName: "",
    passWord: "",
  },
  {
    userName: [{ validator: UserName, trigger: "blur" }],
    passWord: [{ validator: passWord, trigger: "blur" }],
  }
);



const particlesInit = async (engine) => {
  //await loadFull(engine);
  await loadSlim(engine);
};

const particlesLoaded = async (container) => {
  // console.log("Particles container loaded", container);
};

</script>

<style scoped>
.login {
  /* background: rgb(19 60 186); */
}
.card-header {
  text-align: center;
}

.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.box-card {
  width: 340px;
  position: absolute;
  right: 160px;
  top: 200px;
}
</style>
